package com.demo.controller;


import com.demo.dto.QuestionDTO;
import com.demo.dto.Result;
import com.demo.entity.Question;
import com.demo.query.QuestionQuery;
import com.demo.service.QuestionService;
import com.demo.utils.SystemConstants;
import com.demo.vo.QuestionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Zeng
 * @since 2022-03-23
 */
@Api(tags = "问题模块")
@RestController
@RequestMapping("/question")
public class QuestionController {
    @Resource
    QuestionService questionService;

    @ApiOperation("新增问题")
    @PostMapping("/")
    Result<Question> postQuestion(@RequestBody QuestionDTO questionDTO) {
        return questionService.postQuestion(questionDTO);
    }

    @ApiOperation("修改问题")
    @PutMapping("/{id}")
    Result<Question> putQuestion(@PathVariable("id") Integer id, @RequestBody QuestionDTO questionDTO) {
        return questionService.putQuestion(id, questionDTO);
    }

    @ApiOperation("获取问题及其推荐回答")
    @GetMapping("/common/")
    Result<List<QuestionVO>> queryQuestionsByKeyword(
            @RequestParam(value = "keyword", required = false) String keyword,
            @RequestParam(value = "current", defaultValue = "1") Integer current
    ) {
        QuestionQuery questionQuery = new QuestionQuery(keyword, current);
        return questionService.queryQuestionsByKeyword(questionQuery);
    }
}

